package com.ezsoft.dbcputils;
/**
* @author gujianhua
* @version 创建时间：2018年6月27日 下午9:17:54
* 类说明
*/

import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSourceFactory;

public class DbcpUtil {
    private static Properties properties = new Properties();
    private static DataSource dataSource;

    static {
        try {
            FileInputStream is = new FileInputStream("/jdbc.properties");
            properties.load(is);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            dataSource = BasicDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
        Connection connnection = null;
        try {
            connnection = dataSource.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connnection;
    }

    public static void main(String[] args) {
        getConnection();
    }
   
}
